package com.zhuchaooasystem;

import android.os.Handler;
import android.os.Message;
import android.view.WindowManager;

import com.zhuchaooasystem.base.BaseActivity;
import com.zhuchaooasystem.common.Key;
import com.zhuchaooasystem.presenter.MainContract;
import com.zhuchaooasystem.presenter.MainPresenter;
import com.zhuchaooasystem.ui.home.HomeActivity;
import com.zhuchaooasystem.ui.login.LoginActivity;
import com.zhuchaooasystem.utils.AppUtils;

public class MainActivity extends BaseActivity<MainPresenter> implements MainContract.View {

    //如果记住了用户名密码，需要请求接口验证该用户的密码是否有修改，以及该用户是否存在离职等异常信息
    private boolean hasLogin;

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            //登录接口已经验证通过，需要跳转到首页，没验证通过，需要跳转到登录页
            if (hasLogin) {
                AppUtils.jump(MainActivity.this, HomeActivity.class);
            } else {
                AppUtils.jump(MainActivity.this, LoginActivity.class);
            }
            finish();
        }
    };

    @Override
    protected int getLayout() {

        //隐藏状态栏
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        return R.layout.activity_main;
    }

    @Override
    protected MainPresenter getPresenter() {
        return new MainPresenter(mContext, this);
    }

    @Override
    protected void initVariables() {
        hasLogin = false;
        //用户已经登录过
        if (mPresenter.checkLoginState()) {
            mPresenter.login();
        }
    }

    @Override
    protected void initView() {
        Message msg = handler.obtainMessage();
        handler.sendMessageDelayed(msg, Key.WELCOME_TO_HOME);
    }

    @Override
    protected void initDataAndLoadData() {
    }

    @Override
    public void setHasLogin(boolean hasLogin) {
        this.hasLogin = hasLogin;
    }
}
